package com.eboss2.sbs.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.eboss2.sbs.R;
import com.eboss2.sbs.activity.base.BaseActivity;
import com.eboss2.sbs.config.Config;
import com.eboss2.sbs.http.HttpUtil;
import com.eboss2.sbs.myapplication.MyApplication;
import com.loopj.android.http.RequestParams;
import com.mytools.tool.activityManager.MyActivityManager;
import com.mytools.tool.utils.StringUtils;

import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MySettleActivity extends BaseActivity {


    @BindView(R.id.titleback_btn_back)
    LinearLayout titlebackBtnBack;
    @BindView(R.id.tv_accountName)
    TextView tvAccountName;
    @BindView(R.id.tv_bankName)
    TextView tvBankName;
    @BindView(R.id.tv_bank_card)
    TextView tvBankCard;
    @BindView(R.id.tv_bank_address)
    TextView tvBankAddress;
    @BindView(R.id.tv_bank_sub_name)
    TextView tvBankSubName;
    @BindView(R.id.tv_cw_name)
    TextView tvCwName;
    @BindView(R.id.tv_cw_phone)
    TextView tvCwPhone;
    @BindView(R.id.tv_idCard)
    TextView tvIdCard;
//    @BindView(R.id.ll_tx_record)
//    RelativeLayout llTxRecord;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.activity_my_settle);
        ButterKnife.bind(this);
        MyActivityManager.getInstance().addActivity(this);
        initView();
    }

    private void initView() {
        RelativeLayout relativeLayout = relativeLayout(R.id.lv_heard);
        relativeLayout.setBackgroundColor(getResources().getColor(R.color.statusBar));
        showView(R.id.titleback_btn_back, true);
        setTvText(R.id.tv_title, "提现账户信息");
        showView(R.id.next_sure, false);


        getdata();
    }


    private void getdata() {
        showProgress("加载中...");

        String url = Config.SBS_TX_INFO;
        RequestParams params = new RequestParams();
        params.put("shopId", MyApplication.getmInstance().getLoginMEntity().getShopid() + "");

        HttpUtil.get(url, params, new HttpUtil.RequestListener() {

            @SuppressWarnings("unchecked")
            @Override
            public void success(String response) {
                disShowProgress();
                try {


                    JSONObject result = new JSONObject(response);
                    if (!result.optBoolean("status")) {
                        showErrorMsg(result.getString("message"));
                        return;
                    }

                    JSONObject obj = result.getJSONObject("data");

                    String openBank = obj.optString("openBank");
                    String accountName = obj.optString("accountName");
                    String financialName = obj.optString("financialName");
                    String bankNo = obj.optString("bankNo");
                    String openNum = obj.optString("openNum");
                    String financialPhone = obj.optString("financialPhone");
                    String idNo = obj.optString("idNo");
                    String openAdress = obj.optString("openAdress");

                    tvAccountName.setText(StringUtils.isBlank(accountName) ? "" : accountName);
                    tvBankName.setText(StringUtils.isBlank(accountName) ? "" : openBank);
                    tvCwName.setText(StringUtils.isBlank(financialName) ? "" : financialName);
                    tvCwPhone.setText(StringUtils.isBlank(financialPhone) ? "" : financialPhone);
                    tvBankCard.setText(StringUtils.isBlank(bankNo) ? "" : StringUtils.formatCardNo(bankNo));
                    tvBankAddress.setText(StringUtils.isBlank(openAdress) ? "" : openAdress);
                    tvBankSubName.setText(StringUtils.isBlank(openNum) ? "" : openNum);
                    tvIdCard.setText(StringUtils.isBlank(idNo) ? "" : idNo);
                } catch (Exception e) {
                    e.getMessage();

                }
            }

            @Override
            public void failed(Throwable error) {
                disShowProgress();
                showE404();
            }
        });
    }


    @OnClick({R.id.titleback_btn_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.titleback_btn_back:
                finish();
                break;
//            case R.id.ll_tx_record:
//                startActivity(new Intent(mContext, TxRecordActivity.class));
//                break;
        }
    }


}
